<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_display_component_class.php");
    //
    // t_query_result_list
    //
	class t_query_result_list extends t_base_display_component
	{	
		// constant
		// G
		const language_position_last = 1;
        // argoument field name
		const main_url_argument_component_where_values = "component_where_values";
        const main_url_argument_prefix = "prefix";
		// db component parameter name
		const main_query_component_destination_component_where_fields = "destination_component_arg";
		const main_query_component_destination_component_id = "destination_component_id";
        const main_query_component_prefix_url_argument = "prefix_url_argument";
        const main_query_component_source_data_query = "source_data_query";
        const main_query_component_title = "title";

        // query_repository
        const first_query_repository_name = "first_query";
        // S
		const specific_parameters_position_destination_component_where_fields = 1;
		const specific_parameters_position_destination_component_id = 2;
        const specific_parameters_position_prefix_url_argument = 3;
        const specific_parameters_position_source_data_query = 4;
        const specific_parameters_position_title = 5;
        const specific_parameters_position_last = 6; 
        // property
		// public		
		
		// method
		// protected
		//C
		protected function create_tags_structure()
		{
            global $g_javascript_namespace;
			global $g_ambient_namespace;
           // echo "create_tags_structure <BR>";
            // db array parameter									
			try
            {
               // echo "PRIMA: ";
                //var_dump($this->parent_cuteengine_component->main_query_parameter->sql_values);
                    
                       
                    
                // url array
                $this->new_url_argument(self::main_url_argument_prefix,
                    0); 
                $this->new_url_argument(self::main_url_argument_component_where_values."1",
                    1); 
                $this->new_url_argument(self::main_url_argument_component_where_values."2",
                    2);	
                    
                //echo "main_url_argument_prefix:" . $this->url_argument(self::main_url_argument_prefix)."<BR>";
               // echo "main_url_argument_component_where_values:" . $this->url_argument(self::main_url_argument_component_where_values)."<BR>";
                //    
                if (! $this->main_tag)
                {
                    $this->main_tag = new t_base_tag(t_base_tag_type::btt_div,$this->name);
                    $local_header_script_generator = $this->main_tag->header_script_generator;
                    //
                    $this->main_tag->include_child_str = true;
                    $local_header_script_generator->add_style_sheet_property("#$this->name","left","5px");
                    $local_header_script_generator->add_style_sheet_property("#$this->name","top","5px");
                    $local_header_script_generator->add_style_sheet_property("#$this->name","width","100px");
                    $local_header_script_generator->add_style_sheet_property("#$this->name","height","100px");
                    $local_header_script_generator->add_style_sheet_property("#$this->name",'position','fixed');
                    $local_header_script_generator->add_style_sheet_property("#$this->name",'background-color','lightpink');
                    $local_header_script_generator->add_style_sheet_property("#$this->name",'border','1px solid blue');
                    $this->main_tag->set_editing_tags(true);
                    //
                    $local_div_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->name.'_container');
                    $local_header_script_generator->add_style_sheet_property(
                    "#".$local_div_tag->name,'margin-left','auto');	
                    $this->main_container = $local_div_tag;

                    //
                  //  echo "DOPO: ";
                    //var_dump($this->parent_cuteengine_component->main_query_parameter->sql_values);
                    $local_sql = $this->get_main_query_parameter_value(self::main_query_component_source_data_query);
                    //echo "local_sql: $local_sql <BR>";
                    $local_fields_array = explode(':',$local_sql);
                    foreach ($local_fields_array as $local_fields_array_element_index => $local_fields_array_element)
                    {
                        //echo "local_fields_array[$local_fields_array_element_index]: $local_fields_array_element <br>";
                        if (($local_fields_array_element_index % 2) == 1)
                        {
                            $local_sql =  str_replace(":$local_fields_array_element:",
                                    mysqli_real_escape_string($g_ambient_namespace->connection->mysqli,$this->url_argument(self::main_url_argument_component_where_values.
                                        $local_fields_array_element_index)),
                                $local_sql);
                        }
                    }
                    //echo "local_sql: $local_sql";
                    $this->log->add_log_on_page("local_sql: $local_sql");
                    $this->new_query(
                        self::first_query_repository_name,$local_sql,
                        $g_ambient_namespace->connection);

                    // echo "2\n";
                    $this->generate_tag_list();
                    
		
                }
            }    
            catch (Exception $e) 
            {
                //echo $e->getMessage();
                $this->log->add_log_error($e->getMessage());
            }
		}
		// G
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
        static function get_help_specific_parameter($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::specific_parameters_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_specific_parameter($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			switch ($a_index) 
            {
                /*case self::specific_parameters_position_:
					$local_return = 'TRUE';
				break;                */
			}
			return $local_return;
		}	
        protected function get_specific_parameters_position_last()
        {
            return self::specific_parameters_position_last;
        }	
		// I
		protected function initialize_query_parameters()
		{
			 $this->new_query_parameter(
                    t_cuteengine_component::main_query_parameter_name,
                    self::main_query_component_source_data_query,
                    t_cuteengine_component::main_query_field_name_specific_parameters,
                    1);
                $this->new_query_parameter(
                    t_cuteengine_component::main_query_parameter_name,
                    self::main_query_component_destination_component_id,
                    t_cuteengine_component::main_query_field_name_specific_parameters,
                    2);
                $this->new_query_parameter(
                    t_cuteengine_component::main_query_parameter_name,
                    self::main_query_component_destination_component_where_fields,
                    t_cuteengine_component::main_query_field_name_specific_parameters,
                    3);
                $this->new_query_parameter(
                    t_cuteengine_component::main_query_parameter_name,
                    self::main_query_component_title,
                    t_cuteengine_component::main_query_field_name_specific_parameters,
                    4);          
                $this->new_query_parameter(
                    t_cuteengine_component::main_query_parameter_name,
                    self::main_query_component_prefix_url_argument,
                    t_cuteengine_component::main_query_field_name_specific_parameters,
                    5);  
		}		
		// public
		public function __construct($a_cuteengine_component,$a_query_parameter) 
		{
            //echo "__construct PRIMA <BR>";
            parent::__construct($a_cuteengine_component,$a_query_parameter);
                
            //    
			
			//echo "__construct OK <BR>";
			
		}	
		//D
	/*	public function display_component()
		{
			parent::display_component();
		}*/
		// E
		public function execute_component_action()
		{
			$local_function = parent::execute_component_action();
            if ($local_function)
			{
				$this->$local_function();
            }
			else
			{
				 
			}
			//echo "argomento: ".$this->url_argument(self::main_url_argument_import_file_name);
			//$this->parse_source();
		}

	}
?>